﻿# -*- coding: utf-8 -*-
import re
class Config(object):
    """将类似host=xxx;port=xxx;user=xxx;的字符串转换为字典"""
    def __init__(self,str):
        self.dict=Config.Parse(str)
        self.raw=str

    def __getitem__(self,name):
        return self.dict[name]

    def str(self,k,default=''):
        if k in self.dict:
            return str(self[k])
        return default
    
    def int(self,k,default=0):
        if k in self.dict:
            return int(self[k])
        return default

    @staticmethod
    def Parse(str):
        lst=re.findall(r'([^;=]+)=([^;=]+)',str)
        d={}
        for k,v in lst:
            d[k]=v
        return d

